﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Aidbrella.Web.Controllers
{
    public abstract partial class BaseController : Controller
    {
        protected override void OnException(ExceptionContext filterContext)
        {
            // TODO: add logging

            // Output a nice error page
            if (filterContext.HttpContext.IsCustomErrorEnabled)
            {
                string controllerName = (string)filterContext.RouteData.Values["controller"];
                string actionName = (string)filterContext.RouteData.Values["action"];
                HandleErrorInfo model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
                this.ViewData = new ViewDataDictionary<HandleErrorInfo>(model);
                this.TempData = filterContext.Controller.TempData;
                filterContext.ExceptionHandled = true;
                this.View("Error").ExecuteResult(this.ControllerContext);
            }
        }

    }
}
